// Decompiled Using: FrontEnd Plus v2.03 and the JAD Engine
// Available From: http://www.reflections.ath.cx
// Decompiler options: packimports(3) 
// Source File Name:   InitSystemData.java

package dapps.service;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ContextLoaderListener;
import org.springside.modules.utils.DateUtils;

import dapps.dao.proj.ProjDao;
import dapps.entity.proj.Proj;

public class InitSystemData extends ContextLoaderListener implements ServletContextListener  {
	@Autowired
	private ProjDao planManager;
	
	public void setPlanManager(ProjDao planManager) {
		this.planManager = planManager;
	}

	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("web exit ... ");
	}

	@SuppressWarnings("deprecation")
	public void contextInitialized(ServletContextEvent event) {
		System.out.println("web init ... ");
		ServletContext application =  event.getServletContext();

		Integer thisyear = Integer.valueOf(DateUtils.getCurrentDateTime()
				.getYear() + 1900);
		@SuppressWarnings("unused")
		Criterion criterions[] = { Restrictions.gt("yeartime", thisyear) };
		@SuppressWarnings("unused")
		Order orders[] = { Order.desc("yeartime") };
		
		List<Proj> plans = planManager.getAll();
		
		//.FullSearch(null, criterions, null, orders);
			/*//new ArrayList<Plan>();
		Plan pp = new Plan(Integer.valueOf(1999));
		pp.setStatus(1);
		plans.add(pp);*/
		Integer planarray[] = { Integer.valueOf(0), Integer.valueOf(0),
				Integer.valueOf(0) };
		for (Proj p : plans) {
			planarray[0] = p.getApplicate();
		}
/*		for (Plan p : plans) {

			switch (p.getStatus().intValue()) {
			case 1: // '\001'
				planarray[0] = p.getYeartime();
				// fall through

			case 3: // '\003'
				planarray[1] = p.getYeartime();
				// fall through

			case 6: // '\006'
				planarray[2] = p.getYeartime();
				break;
			}
		}*/

		synchronized (application) {
			application.setAttribute("planarray", planarray);
		}
	

	}





}